package cn.tedu.truck.adminsjy.ex.handle;

import cn.tedu.truck.adminsjy.ex.ServiceException;
import cn.tedu.truck.adminsjy.web.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常控制
 *
 * @author num99
 * @version 1.0
 */
@Slf4j
@RestControllerAdvice
public class GlobalHandlerException {
    public GlobalHandlerException(){
        log.info("全局异常控制器 启动!");
    }

    @ExceptionHandler
    public JsonResult handleServiceException(ServiceException e){
        log.warn("捕获到了ServiceException异常:{}",e);
        return JsonResult.fail(e);
    }

    @ExceptionHandler
    public String handleThrowable(Throwable e){
        log.debug("捕获到Throwable：{}", e.getMessage());
        e.printStackTrace(); // 强烈建议
        return "服务器运行过程中出现未知错误，请联系系统管理员！";
    }
}
